package com.example.makerspace.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.makerspace.domain.SingInRecordDO;
import com.example.makerspace.domain.TaskFinishDO;
import com.example.makerspace.mapper.TaskFinishMapper;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class TaskFinishDAO extends  BaseDAO<TaskFinishDO> {
    @Resource
    private TaskFinishMapper taskFinishMapper;

    private  static  final  String USERNAME="username";

    @PostConstruct
    public void init(){
        this.mapper = taskFinishMapper;
    }

    public void deleteByTaskId(Integer id) {
        QueryWrapper<TaskFinishDO> wrapper = new QueryWrapper<>();
        wrapper.eq("task_id",id);
        mapper.delete(wrapper);
    }

    public TaskFinishDO selecByTaskAndUser(Integer id, String username) {
        QueryWrapper<TaskFinishDO> wrapper = new QueryWrapper<>();
        wrapper.eq("task_id",id).eq("username",username).eq("is_finish",0);
        return  mapper.selectOne(wrapper);
    }

    public void deleteByUsername(String username) {
        mapper.delete(new QueryWrapper<TaskFinishDO>().eq(USERNAME,username));
    }
}
